package com.caregiver.watch.business.care.controller;

import com.caregiver.watch.business.care.model.vo.ActivityDataVo;
import com.caregiver.watch.business.care.model.vo.BloodOxygenDetailDataVo;
import com.caregiver.watch.business.care.model.vo.HeartRriDetailDataVo;
import com.caregiver.watch.business.care.model.vo.SportDataDetailVo;
import com.caregiver.watch.business.care.model.vo.TemperatureDetailDataVo;
import com.caregiver.watch.business.care.model.vo.TodaySportDataVo;
import com.caregiver.watch.business.care.model.vo.BloodPressureDetailDataVo;
import com.caregiver.watch.business.care.model.vo.EcgDetailDataVo;
import com.caregiver.watch.business.care.model.vo.HealthDataVo;
import com.caregiver.watch.business.care.model.vo.HeartRateDetailVo;
import com.caregiver.watch.business.care.model.vo.LocationDataVo;
import com.caregiver.watch.business.care.model.vo.SleepDetailVo;
import com.caregiver.watch.business.care.model.vo.SportDataVo;
import com.caregiver.watch.business.care.model.vo.StressValueDetailDataVo;
import com.caregiver.watch.business.care.model.vo.TraceVo;
import com.caregiver.watch.business.care.model.vo.WeekActivityDataVo;
import com.caregiver.watch.business.care.model.vo.WeekSleepDetailVo;
import com.caregiver.watch.business.care.service.HealthService;
import com.caregiver.watch.common.domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 用户监护数据
 * @Author 疆戟
 * @Date 2025/9/20 10:01
 * @Version 1.0
 */
@Tag(name  = "CareHealthDataController", description = "监护健康数据")
@RestController
@RequestMapping("/care/health/data")
@Slf4j
public class CareHealthDataController {

    @Autowired
    private HealthService healthService;

    @Operation(summary = "获取用户今天的运动数据", description = "获取用户今天的运动数据")
    @GetMapping(value = "getTodaySportData")
    public R<TodaySportDataVo> getTodaySportData(@RequestParam(value = "deviceUuid") String deviceUuid) {
        return R.ok(healthService.getTodaySportData(deviceUuid));
    }

    // 获取运动数据
    @Operation(summary = "获取运动数据", description = "获取运动数据")
    @GetMapping(value = "getSportData")
    public R<List<SportDataVo>> getSportData(@RequestParam(value = "deviceUuid") String deviceUuid) {
        return R.ok(healthService.getSportData(deviceUuid));
    }

    // 获取用户定位数据
    @Operation(summary = "获取定位数据", description = "获取定位数据")
    @GetMapping(value = "getLocationData")
    public R<LocationDataVo> getLocationData(@RequestParam(value = "deviceUuid") String deviceUuid) {
        return R.ok(healthService.getLocationData(deviceUuid));
    }

    // 统计存在用户轨迹的日期
    @Operation(summary = "查询存在用户轨迹的日期(1月1日和1月2日返回[1,2])", description = "查询存在用户轨迹的日期")
    @GetMapping(value = "queryExistTraceDate")
    public R<List<Integer>> queryExistTraceDate(@RequestParam(value = "deviceUuid") String deviceUuid,
                                                @RequestParam(value = "dataTime") String dataTime) {
        return R.ok(healthService.queryExistTraceDate(deviceUuid, dataTime));
    }


    // 查询用户轨迹
    @Operation(summary = "查询轨迹", description = "查询轨迹")
    @GetMapping(value = "queryTrace")
    public R<TraceVo> queryTrace(@RequestParam(value = "deviceUuid") String deviceUuid,
                                 @RequestParam(value = "startTime") String startTime,
                                 @RequestParam(value = "endTime") String endTime) {
        return R.ok(healthService.queryTrace(deviceUuid, startTime, endTime));
    }


    // 获取用户健康数据
    @Operation(summary = "获取用户健康数据", description = "获取用户健康数据")
    @GetMapping(value = "getHealthData")
    public R<HealthDataVo> getHealthData(@RequestParam(value = "deviceUuid") String deviceUuid) {
        return R.ok(healthService.getHealthData(deviceUuid));
    }

    @Operation(summary = "获取用户睡眠详情数据", description = "获取用户睡眠详情数据")
    @GetMapping(value = "getSleepDetailData")
    public R<SleepDetailVo> getSleepDetailData(@RequestParam(value = "deviceUuid") String deviceUuid,
                                               @RequestParam(value = "dataTime") String dataTime) {
        return R.ok(healthService.getSleepDetailData(deviceUuid, dataTime));
    }

    @Operation(summary = "获取用户一周的睡眠详情数据", description = "获取用户一周的睡眠详情数据")
    @GetMapping(value = "getWeekSleepDetailData")
    public R<WeekSleepDetailVo> getWeekSleepDetailData(@RequestParam(value = "deviceUuid") String deviceUuid,
                                                       @RequestParam(value = "startTime") String startTime,
                                                       @RequestParam(value = "endTime") String endTime) {
        return R.ok(healthService.getWeekSleepDetailData(deviceUuid, startTime, endTime));
    }

    // 获取心率详情数据
    @Operation(summary = "获取心率详情数据", description = "获取心率详情数据")
    @GetMapping(value = "getHeartRateDetailData")
    public R<HeartRateDetailVo> getHeartRateDetailData(@RequestParam(value = "deviceUuid") String deviceUuid,
                                                       @RequestParam(value = "dataTime") String dataTime) {
        return R.ok(healthService.getHeartRateDetailData(deviceUuid, dataTime));
    }


    // 获取血压数据详情数据
    @Operation(summary = "获取血压数据详情数据", description = "获取血压数据详情数据")
    @GetMapping(value = "getBloodPressureDetailData")
    public R<BloodPressureDetailDataVo> getBloodPressureDetailData(@RequestParam(value = "deviceUuid") String deviceUuid,
                                                                   @RequestParam(value = "dataTime") String dataTime) {
        return R.ok(healthService.getBloodPressureDetailData(deviceUuid, dataTime));
    }

    // 获取压力值详情数据
    @Operation(summary = "获取压力值详情数据", description = "获取压力值详情数据")
    @GetMapping(value = "getStressValueDetailData")
    public R<StressValueDetailDataVo> getStressValueDetailData(@RequestParam(value = "deviceUuid") String deviceUuid,
                                                               @RequestParam(value = "dataTime") String dataTime) {
        return R.ok(healthService.getStressValueDetailData(deviceUuid, dataTime));
    }

    // 获取用户心电详情数据
    @Operation(summary = "获取用户心电详情数据", description = "获取用户心电详情数据")
    @GetMapping(value = "getEcgDetailData")
    public R<EcgDetailDataVo> getEcgDetailData(@RequestParam(value = "deviceUuid") String deviceUuid,
                                               @RequestParam(value = "dataTime") String dataTime) {
        return R.ok(healthService.getEcgDetailData(deviceUuid, dataTime));
    }

    // 血氧
    @Operation(summary = "获取血氧数据详情数据", description = "获取血氧数据详情数据")
    @GetMapping(value = "getBloodOxygenDetailData")
    public R<BloodOxygenDetailDataVo> getBloodOxygenDetailData(@RequestParam(value = "deviceUuid") String deviceUuid,
                                                               @RequestParam(value = "dataTime") String dataTime){
        return R.ok(healthService.getBloodOxygenDetailData(deviceUuid, dataTime));
    }

    // 体温
    @Operation(summary = "获取体温数据详情数据", description = "获取体温数据详情数据")
    @GetMapping(value = "getTemperatureDetailData")
    public R<TemperatureDetailDataVo> getTemperatureDetailData(@RequestParam(value = "deviceUuid") String deviceUuid,
                                                               @RequestParam(value = "dataTime") String dataTime){
        return R.ok(healthService.getTemperatureDetailData(deviceUuid, dataTime));
    }

    // 获取运动数据详情
    @Operation(summary = "获取运动数据详情", description = "获取运动数据详情")
    @GetMapping(value = "getSportDataDetail")
    public R<SportDataDetailVo> getSportDataDetail(@Parameter(description = "设备UUID", required = true, example = "device-123") @RequestParam(value = "deviceUuid") String deviceUuid,
                                                   @Parameter(description = "查询时间", required = true, example = "yyyy-MM-dd")  @RequestParam(value = "dataTime") String dataTime) {
        return R.ok(healthService.getSportDataDetail(deviceUuid, dataTime));
    }

    //获取的运行详情
    @Operation(summary = "获取运动详情", description = "获取运动详情")
    @GetMapping(value = "getSportDataDetailV2")
    public R<SportDataDetailVo> getSportDataDetailV2(@Parameter(description = "设备UUID", required = true, example = "device-123") @RequestParam(value = "deviceUuid") String deviceUuid,
                                                     @Parameter(description = "查询起始时间", required = true, example = "yyyy-MM-dd")  @RequestParam(value = "startTime") String startTime,
                                                     @Parameter(description = "查询结束时间", required = true, example = "yyyy-MM-dd" ) @RequestParam(value = "endTime") String endTime) {
        return R.ok(healthService.getSportDataDetailV2(deviceUuid, startTime, endTime));
    }

    // 获取活动数据
    @Operation(summary = "获取活动数据", description = "获取活动数据")
    @GetMapping(value = "getActivityData")
    public R<ActivityDataVo> getActivityData(@Parameter(description = "设备UUID", required = true, example = "device-123") @RequestParam(value = "deviceUuid") String deviceUuid,
                                             @Parameter(description = "查询时间", required = true, example = "yyyy-MM-dd") @RequestParam(value = "dataTime") String dataTime) {
        return R.ok(healthService.getActivityData(deviceUuid, dataTime));
    }

    // 获取一周的活动数据
    @Operation(summary = "获取一周的活动数据", description = "获取一周的活动数据")
    @GetMapping(value = "getWeekActivityData")
    public R<WeekActivityDataVo> getWeekActivityData(@Parameter(description = "设备UUID", required = true, example = "device-123") @RequestParam(value = "deviceUuid") String deviceUuid,
                                                     @Parameter(description = "查询时间", required = true, example = "yyyy-MM-dd") @RequestParam(value = "startTime") String startTime,
                                                     @Parameter(description = "查询时间", required = true, example = "yyyy-MM-dd") @RequestParam(value = "endTime") String endTime) {
        return R.ok(healthService.getWeekActivityData(deviceUuid, startTime, endTime));
    }


    // 查询心脏健康详情数据
    @Operation(summary = "查询房颤数据详情数据", description = "查询房颤数据详情数据")
    @GetMapping(value = "getHeartRriDetailData")
    public R<HeartRriDetailDataVo> getHeartRriDetailData(@RequestParam(value = "deviceUuid") String deviceUuid,
                                                         @RequestParam(value = "dataTime") String dataTime) {
        return R.ok(healthService.getHeartRriDetailData(deviceUuid, dataTime));
    }
}
